#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 305;
int n,m,t;
int map[maxn][maxn];

int main(){

	cin>>n>>m>>t;
	int x,y,z;
	memset(map,0x7f,sizeof map);
	for(int i=1;i<=m;i++){
		cin>>x>>y>>z;
		map[x][y]=z;
	}
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(k!=i && i!=j && j!=k)map[i][j]=min(map[i][j],max(map[i][k],map[k][j]));
			} 
		}
	}
	for(int i=1;i<=t;i++){
		cin>>x>>y;
		if(map[x][y]>=1000000)cout<<-1<<endl;
		else cout<<map[x][y]<<endl;
	}
	return 0;
}
